package com.blue.core.config;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.w3c.dom.Element;

/**
 * TaskExecutor解析器
 *
 * @author Jin Zheng
 * @date 2018-10-26
 */
public class TaskExecutorParser extends AbstractSimpleBeanDefinitionParser
{
	public TaskExecutorParser()
	{
	}

	@Override
	protected Class<?> getBeanClass(Element element)
	{
		return ThreadPoolTaskExecutor.class;
	}

	@Override
	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
	{
		try
		{
			builder.addPropertyValue("corePoolSize", element.getAttribute("core-pool-size"));
			builder.addPropertyValue("maxPoolSize", element.getAttribute("max-pool-size"));
			builder.addPropertyValue("queueCapacity", element.getAttribute("queue-capacity"));
			builder.addPropertyValue("keepAliveSeconds", element.getAttribute("keep-alive-seconds"));
		}
		catch (Exception e)
		{
			parserContext.getReaderContext().error(ThreadPoolTaskExecutor.class.getName() + " 无法创建", element, null, e);
		}
	}
}
